home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Network Co229257172001.psc / Icmp.bas < prev    next >
Encoding:
BASIC Source File  |  2001-07-17  |  6.8 KB  |  223 lines

  1. Attribute VB_Name = "ICMP"
  2. Option Explicit
  3. Global closecount
  4. #If Win16 Then
  5.     Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer)
  6. #Else
  7.     Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  8. #End If
  9. 'MY CODE
  10. Public Computers(199) As String
  11. Public Ips(199) As String
  12. Public totalips As Integer
  13. Public indexit As String
  14. Public turnoff As Integer
  15. 'END OF MY CODE
  16. Public Const IP_STATUS_BASE = 11000
  17. Public Const IP_SUCCESS = 0
  18. Public Const IP_BUF_TOO_SMALL = (11000 + 1)
  19. Public Const IP_DEST_NET_UNREACHABLE = (11000 + 2)
  20. Public Const IP_DEST_HOST_UNREACHABLE = (11000 + 3)
  21. Public Const IP_DEST_PROT_UNREACHABLE = (11000 + 4)
  22. Public Const IP_DEST_PORT_UNREACHABLE = (11000 + 5)
  23. Public Const IP_NO_RESOURCES = (11000 + 6)
  24. Public Const IP_BAD_OPTION = (11000 + 7)
  25. Public Const IP_HW_ERROR = (11000 + 8)
  26. Public Const IP_PACKET_TOO_BIG = (11000 + 9)
  27. Public Const IP_REQ_TIMED_OUT = (11000 + 10)
  28. Public Const IP_BAD_REQ = (11000 + 11)
  29. Public Const IP_BAD_ROUTE = (11000 + 12)
  30. Public Const IP_TTL_EXPIRED_TRANSIT = (11000 + 13)
  31. Public Const IP_TTL_EXPIRED_REASSEM = (11000 + 14)
  32. Public Const IP_PARAM_PROBLEM = (11000 + 15)
  33. Public Const IP_SOURCE_QUENCH = (11000 + 16)
  34. Public Const IP_OPTION_TOO_BIG = (11000 + 17)
  35. Public Const IP_BAD_DESTINATION = (11000 + 18)
  36. Public Const IP_ADDR_DELETED = (11000 + 19)
  37. Public Const IP_SPEC_MTU_CHANGE = (11000 + 20)
  38. Public Const IP_MTU_CHANGE = (11000 + 21)
  39. Public Const IP_UNLOAD = (11000 + 22)
  40. Public Const IP_ADDR_ADDED = (11000 + 23)
  41. Public Const IP_GENERAL_FAILURE = (11000 + 50)
  42. Public Const MAX_IP_STATUS = 11000 + 50
  43. Public Const IP_PENDING = (11000 + 255)
  44. Public Const PING_TIMEOUT = 200
  45. Public Const WS_VERSION_REQD = &H101
  46. Public Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&
  47. Public Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
  48. Public Const MIN_SOCKETS_REQD = 1
  49. Public Const SOCKET_ERROR = -1
  50.  
  51. Public Const MAX_WSADescription = 256
  52. Public Const MAX_WSASYSStatus = 128
  53.  
  54. Public Type ICMP_OPTIONS
  55. Ttl As Byte
  56. Tos As Byte
  57. Flags As Byte
  58. OptionsSize As Byte
  59. OptionsData As Long
  60. End Type
  61.  
  62. Dim ICMPOPT As ICMP_OPTIONS
  63.  
  64. Public Type ICMP_ECHO_REPLY
  65. Address As Long
  66. status As Long
  67. RoundTripTime As Long
  68. DataSize As Integer
  69. Reserved As Integer
  70. DataPointer As Long
  71. Options As ICMP_OPTIONS
  72. Data As String * 250
  73. End Type
  74.  
  75. Public Type HOSTENT
  76. hName As Long
  77. hAliases As Long
  78. hAddrType As Integer
  79. hLen As Integer
  80. hAddrList As Long
  81. End Type
  82.  
  83. Public Type WSADATA
  84. wVersion As Integer
  85. wHighVersion As Integer
  86. szDescription(0 To MAX_WSADescription) As Byte
  87. szSystemStatus(0 To MAX_WSASYSStatus) As Byte
  88. wMaxSockets As Integer
  89. wMaxUDPDG As Integer
  90. dwVendorInfo As Long
  91. End Type
  92.  
  93.  
  94. Public Declare Function IcmpCreateFile Lib "icmp.dll" () As Long
  95.  
  96. Public Declare Function IcmpCloseHandle Lib "icmp.dll" _
  97. (ByVal IcmpHandle As Long) As Long
  98.  
  99. Public Declare Function IcmpSendEcho Lib "icmp.dll" _
  100. (ByVal IcmpHandle As Long, _
  101. ByVal DestinationAddress As Long, _
  102. ByVal RequestData As String, _
  103. ByVal RequestSize As Integer, _
  104. ByVal RequestOptions As Long, _
  105. ReplyBuffer As ICMP_ECHO_REPLY, _
  106. ByVal ReplySize As Long, _
  107. ByVal Timeout As Long) As Long
  108.  
  109. Public Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As Long
  110.  
  111. Public Declare Function WSAStartup Lib "WSOCK32.DLL" _
  112. (ByVal wVersionRequired As Long, _
  113. lpWSADATA As WSADATA) As Long
  114.  
  115. Public Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
  116.  
  117. Public Declare Function gethostname Lib "WSOCK32.DLL" _
  118. (ByVal szHost As String, _
  119. ByVal dwHostLen As Long) As Long
  120.  
  121. Public Declare Function gethostbyname Lib "WSOCK32.DLL" _
  122. (ByVal szHost As String) As Long
  123.  
  124. Public Declare Sub RtlMoveMemory Lib "kernel32" _
  125. (hpvDest As Any, _
  126. ByVal hpvSource As Long, _
  127. ByVal cbCopy As Long)
  128.  
  129.  
  130. Public Function GetStatusCode(status As Long) As String
  131.  
  132. Dim msg As String
  133.  
  134. Select Case status
  135. Case IP_SUCCESS: msg = "ip success"
  136. Case IP_BUF_TOO_SMALL: msg = "ip buf too_small"
  137. Case IP_DEST_NET_UNREACHABLE: msg = "ip dest net unreachable"
  138. Case IP_DEST_HOST_UNREACHABLE: msg = "ip dest host unreachable"
  139. Case IP_DEST_PROT_UNREACHABLE: msg = "ip dest prot unreachable"
  140. Case IP_DEST_PORT_UNREACHABLE: msg = "ip dest port unreachable"
  141. Case IP_NO_RESOURCES: msg = "ip no resources"
  142. Case IP_BAD_OPTION: msg = "ip bad option"
  143. Case IP_HW_ERROR: msg = "ip hw_error"
  144. Case IP_PACKET_TOO_BIG: msg = "ip packet too_big"
  145. Case IP_REQ_TIMED_OUT: msg = "ip req timed out"
  146. Case IP_BAD_REQ: msg = "ip bad req"
  147. Case IP_BAD_ROUTE: msg = "ip bad route"
  148. Case IP_TTL_EXPIRED_TRANSIT: msg = "ip ttl expired transit"
  149. Case IP_TTL_EXPIRED_REASSEM: msg = "ip ttl expired reassem"
  150. Case IP_PARAM_PROBLEM: msg = "ip param_problem"
  151. Case IP_SOURCE_QUENCH: msg = "ip source quench"
  152. Case IP_OPTION_TOO_BIG: msg = "ip option too_big"
  153. Case IP_BAD_DESTINATION: msg = "ip bad destination"
  154. Case IP_ADDR_DELETED: msg = "ip addr deleted"
  155. Case IP_SPEC_MTU_CHANGE: msg = "ip spec mtu change"
  156. Case IP_MTU_CHANGE: msg = "ip mtu_change"
  157. Case IP_UNLOAD: msg = "ip unload"
  158. Case IP_ADDR_ADDED: msg = "ip addr added"
  159. Case IP_GENERAL_FAILURE: msg = "ip general failure"
  160. Case IP_PENDING: msg = "ip pending"
  161. Case PING_TIMEOUT: msg = "ping timeout"
  162. Case Else: msg = "unknown msg returned"
  163. End Select
  164.  
  165. GetStatusCode = CStr(status) & " [ " & msg & " ]"
  166.  
  167. End Function
  168.  
  169.  
  170. Public Function HiByte(ByVal wParam As Integer)
  171.  
  172. HiByte = wParam \ &H100 And &HFF&
  173.  
  174. End Function
  175.  
  176.  
  177. Public Function LoByte(ByVal wParam As Integer)
  178.  
  179. LoByte = wParam And &HFF&
  180.  
  181. End Function
  182.  
  183.  
  184. Public Function Ping(szAddress As String, ECHO As ICMP_ECHO_REPLY) As Long
  185.  
  186. Dim hPort As Long
  187. Dim dwAddress As Long
  188. Dim sDataToSend As String
  189. Dim iOpt As Long
  190.  
  191. 'The data to be sent can be changed to anything
  192. 'Packet sizes will gretly affect the outcome of the ping
  193. sDataToSend = "Echo This"
  194. dwAddress = AddressStringToLong(szAddress)
  195.  
  196. Call SocketsInitialize
  197. hPort = IcmpCreateFile()
  198.  
  199. If IcmpSendEcho(hPort, _
  200. dwAddress, _
  201. sDataToSend, _
  202. Len(sDataToSend), _
  203. 0, _
  204. ECHO, _
  205. Len(ECHO), _
  206. PING_TIMEOUT) Then
  207.  
  208. 'the ping succeeded,
  209. '.Status will be 0
  210. '.RoundTripTime is the time in ms for
  211. ' the ping to complete,
  212. '.Data is the data returned (NULL terminated)
  213. '.Address is the Ip address that actually replied
  214. '.DataSize is the size of the string in .Data
  215. Ping = ECHO.RoundTripTime
  216. Else: Ping = ECHO.status *END OEl wm.stat_lDDR_ADDED: msg = "ip addr addeeat_lDDR_ADDED: msgPACKET_TOO_BIG: msg = "ip packet too"hlDDR_ADDED: msg = "ip a.tE: O
  217. Ca.ded"
  218. Case ED_
  219. Gi6pTeIE ED_l ICMreturned"
  220. EndTFGi6pTeIE ED_l ICMretu<)LongE ED_Timened"
  221. EndTFG
  222. Case ED_sTblicN7LaS
  223.